package org.stu.tp.testCases.contact;

import org.stu.tp.core.DefaultAjaxSelenium;
import org.stu.tp.dto.Contact;
import org.stu.tp.dto.Email;
import org.stu.tp.dto.Phone;

public class ContactAction extends ContactSac {

	/**
	 * set contact details, include the contact name.
	 * 
	 * @param selenium
	 * @param contact
	 */
	public void setContactInfo(DefaultAjaxSelenium selenium, Contact contact) {
		this.setName(selenium, contact.getName());
		this.setCompany(selenium, contact.getCompany());
		this.setDepart(selenium, contact.getDepart());
		this.setRealName(selenium, contact.getRealName());
		this.setBorn(selenium, contact.getBorn());
		this.setSex(selenium, contact.getSex());
		this.setAddress(selenium, contact.getAddress());
		this.setRemark(selenium, contact.getRemark());
	}

	/**
	 * Set the contact phone.
	 * 
	 * @param selenium
	 * @param index
	 * @param phone
	 */
	public void setContactPhone(DefaultAjaxSelenium selenium, String index,
			Phone phone) throws Exception{
		String stateValue="";
		this.setPhoneNumber(selenium, index, phone.getNumber());
		this.setPhoneType(selenium, index, phone.getType());
		stateValue=this.getPhoneState(selenium, index);
		this.setPhoneProvince(selenium, index, phone.getProvince());
		for(int i=0;i<=60;i++){
			if(stateValue.equals(this.getPhoneState(selenium, index))){
				Thread.sleep(5000);
			}else{
				break;
			}
		}
		this.setPhoneState(selenium, index, phone.getState());
	}

	/**
	 * Set contact email.
	 * 
	 * @param selenium
	 * @param index
	 * @param email
	 */
	public void setContactEmail(DefaultAjaxSelenium selenium, String index,
			Email email) {
		this.setEmailValue(selenium, index, email.getEmail());
		this.setEmailType(selenium, index, email.getType());
	}
	
	public boolean isContactExist(DefaultAjaxSelenium selenium,Contact contact){
		return selenium.isElementPresent("link="+contact.getName());
	}

}
